

# 序列的第一位都是从 0  开始取第一位元素， -1 从最后一位取元素
x = [1, 2, 3, 9, 8, 7]
print(x[0])
print(x[-1])
# print(x[-11])


z = [1, 2, 3, 9, 8, 7]
print(z[2:4])
print(z[ 2:])
print(z[ :4])
print(z[ :44])




# 字符串也是序列的一种，所以也可以被索引
y = "abcde"
print(y[0])

z = [1, 2, 3, 9, 8, 7]
print(z[: :3])

# -1的步长是从后向前分片，取8元素，弃掉3元素
a = [1, 2, 3, 4, 5 ,6, 7, 8, 9, 10]
# print(a[8:3:-1])
# 反向分片，元素大小越界会返回空列表
print(a[::3])

# 列表相加
a = [1, 2, 3]
b = [4, 5, 6]
print("列表a + b:",a + b)

print('python,' * 5)
print([32] * 5)


# 检查值是否在某个序列中
word = "hello,wolrd"
print('llqwe' in word)

list1 = [1, "1", 2, 3, 4, 5 ,6, 7, 8, 9, 10]
print( "12" in list1)



database = [["zkk", "123"], ["zkk1", "456"],["zkk2", "456"]]
username = input("请输入用户名：")
password = input("请输入密码：")
if [username, password] in database:
    print("Access granted")
else:
    print('输入信息有误！')


#列表的长度
a = [1, 2, 3]
ab = ["ab","v","t"]
abc = "abcde"
print("列表a的元素个数：",len(a))
print("列表a的元素中最大值：", max(a))
print("列表a的元素中最小值：", min(a))
print("列表ab的元素个数：",len(ab))
print("列表ab的元素中最大值：", max(ab))
print("列表ab的元素中最小值：", min(ab))
print(len(abc))

#
aa = [1, 2, 3]
bb = ["abc", "Abc", "ABc", "ABC"]
# print(len(aa))
print(len(bb))
# print(min(aa))
print(min(bb))
# print(max(aa))
print(max(bb))

def list(list):
    a = 0
    if list[a] is True:
        a = +1
        print(a)
    else:
        return a
list(aa)


list()



# 通过list方法将字符串转换成列表
c = "hello,world!"
print(list(c))
print(type(c))

# 通过索引的方式改变列表中的元素
xxx = [1, 2, 3, 4, 5]
xxx[1] = 6
# xxx[7] = 6   #不要给一个越界的元素赋值


print("对xxx[1]的解释", [1, 2, 3, 4, 5][1])



print(xxx)

#删除元素
names = ["Alice", "Beth", "Cecil", "Dee-Dee"]
print(names)
del names[1]
print(names)

#分片赋值
names1 = ['p', 'e', 't', 't', 'e', 'r']
print(names1)
names1[4:] = ['y']
print(names1)


#append（）在列表最后追加新的元素

x1 = [1, 2, 3, 4]
x1.append(5)
print(x1)


c4 = input("please int")
print(type(c4))
c5 = []
c5.append(int(c4))
print(c5)

# count() 统计 某个元素在列表中出现的次数
x = [[1, 2], 1, 1, [2, 1, [1, 23], 1], 1]
x1 = x.count(1)
print(x1)

# 组合列表：将列表的元素追加到另一个列表的尾部 extend()
x = [1, 2, 3, 4, 5]
y = [6, 7, 8, 9, 10]
x.extend(y)
print(x)

# 8、查找出元素在列表中第一次匹配到的索引位置   index（）
x5 = ["we", "are", "the", "knights", "who", "say", "ni", "who"]
x55 = x5.index("who")
print(x55)
print(x5.index("who"))

# 将对象插入到列表中 insert()
number1 = [1, 2, 3, 4]
number1.insert(3, "abc")
print(number1)
number1[3:3] = ["def"]
print(number1)

# 移除列表中最后一个元素，并且返回这个元素的值，pop()       后进先出原则       append()------pop()  相反
number2 = [1, 2, 3, 4]
print(number2.pop())
print(number2.pop())

number3 = [1, 2, 3, 4, 5]
print(number3.pop(1))

# 移除列表中某个值的第一个匹配项 remove（）
number3 = [1, 2, 3, 4, 5]
print("原列表值：", number3)
number3.remove(2)    # 对列表进行了值为2的第一个匹配项的移除操作，不返回结果
print("remove后的列表值：", number3)

# 12、将列表的元素反转 reverse()
number4 = [1, 2, 3, 4, 5]
number4.reverse()
print(number4)

# 在原来的列表上进行排序  sort()  正序
number5 = [6, 2, 4, 5, 3]
number5.sort()
print(number5)
number5.reverse()
print(number5)



number6 = [6, 2, 4, 5, 3]
number7 = number6[:]    #取出所有元素赋值给number7中， 直接number7 = number6 都指向了同一个内存地址，这样是无效的
number7.sort()
print(number6)
print(number7)

############# sorted() 方法
zbc = [45, 3 ,23, 9, 92]
print(sorted(zbc))